 package server.maps.pvp;

 import client.MapleBuffStat;
 import client.MapleCharacter;
 import client.skills.Skill;
 import client.skills.SkillFactory;
 import handling.channel.handler.AttackInfo;
 import handling.world.WorldBroadcastService;
 import handling.world.WorldGuildService;
 import java.awt.Point;
 import java.awt.Rectangle;
 import server.MapleStatEffect;
 import server.life.MapleLifeFactory;
 import server.life.MapleMonster;
 import server.maps.MapleMap;
 import tools.MaplePacketCreator;
 import tools.Randomizer;












 public class MaplePvp
 {
   private static PvpAttackInfo parsePvpAttack(AttackInfo attack, MapleCharacter player, MapleStatEffect effect) {
/*  33 */     PvpAttackInfo ret = new PvpAttackInfo();
/*  34 */     double maxdamage = player.getLevel() + 100.0D;
/*  35 */     int skillId = attack.skillId;
/*  36 */     ret.skillId = skillId;
/*  37 */     ret.critRate = 5;
/*  38 */     ret.ignoreDef = 0;
/*  39 */     ret.skillDamage = 100;
/*  40 */     ret.mobCount = 1;
/*  41 */     ret.attackCount = 1;
/*  42 */     int pvpRange = attack.isCloseRangeAttack ? 35 : 70;
/*  43 */     ret.facingLeft = (attack.direction < 0);
/*  44 */     if (skillId != 0 && effect != null) {
/*  45 */       ret.critRate += effect.getCritical();
/*  46 */       ret.ignoreDef += effect.getIgnoreMob();
/*  47 */       ret.skillDamage = effect.getDamage() + player.getStat().getDamageIncrease(skillId);
/*  48 */       ret.mobCount = Math.max(1, effect.getMobCount(player));
/*  49 */       ret.attackCount = Math.max(effect.getBulletCount(player), effect.getAttackCount(player));
/*  50 */       ret.box = effect.calculateBoundingBox(player.getTruePosition(), ret.facingLeft, pvpRange);
     } else {
/*  52 */       ret.box = calculateBoundingBox(player.getTruePosition(), ret.facingLeft, pvpRange);
     }
/*  54 */     boolean mirror = (player.getBuffedValue(MapleBuffStat.影分身) != null || player.getBuffedIntValue(MapleBuffStat.月光转换) == 1);
/*  55 */     ret.attackCount *= mirror ? 2 : 1;
/*  56 */     maxdamage *= ret.skillDamage / 100.0D;
/*  57 */     ret.maxDamage = maxdamage * ret.attackCount;
/*  58 */     if (player.isShowPacket()) {
/*  59 */       player.dropSpouseMessage(10, "Pvp伤害解析 - 最大攻击: " + maxdamage + " 数量: " + ret.mobCount + " 次数: " + ret.attackCount + " 爆击: " + ret.critRate + " 无视: " + ret.ignoreDef + " 技能伤害: " + ret.skillDamage);
     }
/*  61 */     return ret;
   }

   private static Rectangle calculateBoundingBox(Point posFrom, boolean facingLeft, int range) {
/*  65 */     Point mylt, myrb, lt = new Point(-70, -30);
/*  66 */     Point rb = new Point(-10, 0);


/*  69 */     if (facingLeft) {
/*  70 */       mylt = new Point(lt.x + posFrom.x - range, lt.y + posFrom.y);
/*  71 */       myrb = new Point(rb.x + posFrom.x, rb.y + posFrom.y);
     } else {
/*  73 */       myrb = new Point(lt.x * -1 + posFrom.x + range, rb.y + posFrom.y);
/*  74 */       mylt = new Point(rb.x * -1 + posFrom.x, lt.y + posFrom.y);
     }
/*  76 */     return new Rectangle(mylt.x, mylt.y, myrb.x - mylt.x, myrb.y - mylt.y);
   }

   public static boolean inArea(MapleCharacter chr) {
/*  80 */     for (Rectangle rect : chr.getMap().getAreas()) {
/*  81 */       if (rect.contains(chr.getTruePosition())) {
/*  82 */         return true;
       }
     }
/*  85 */     return false;
   }

   private static void monsterBomb(MapleCharacter player, MapleCharacter attacked, MapleMap map, PvpAttackInfo attack) {
/*  89 */     if (player == null || attacked == null || map == null) {
       return;
     }
/*  92 */     double maxDamage = attack.maxDamage;
/*  93 */     boolean isCritDamage = false;

/*  95 */     if (player.getLevel() > attacked.getLevel() + 10) {
/*  96 */       maxDamage *= 1.05D;
/*  97 */     } else if (player.getLevel() < attacked.getLevel() - 10) {
/*  98 */       maxDamage /= 1.05D;
/*  99 */     } else if (player.getLevel() > attacked.getLevel() + 20) {
/* 100 */       maxDamage *= 1.1D;
/* 101 */     } else if (player.getLevel() < attacked.getLevel() - 20) {
/* 102 */       maxDamage /= 1.1D;
/* 103 */     } else if (player.getLevel() > attacked.getLevel() + 30) {
/* 104 */       maxDamage *= 1.15D;
/* 105 */     } else if (player.getLevel() < attacked.getLevel() - 30) {
/* 106 */       maxDamage /= 1.15D;
     }

/* 109 */     if (Randomizer.nextInt(100) < attack.critRate) {
/* 110 */       maxDamage *= 1.5D;
/* 111 */       isCritDamage = true;
     }
/* 113 */     int attackedDamage = (int)Math.floor(Math.random() * (int)maxDamage * 0.35D + (int)maxDamage * 0.65D);
/* 114 */     int MAX_PVP_DAMAGE = (int)(player.getStat().getLimitBreak(player) / 100.0D);
/* 115 */     int MIN_PVP_DAMAGE = 100;
/* 116 */     if (attackedDamage > MAX_PVP_DAMAGE) {
/* 117 */       attackedDamage = MAX_PVP_DAMAGE;
     }
/* 119 */     if (attackedDamage < MIN_PVP_DAMAGE) {
/* 120 */       attackedDamage = MIN_PVP_DAMAGE;
     }
/* 122 */     int hploss = attackedDamage, mploss = 0;
/* 123 */     if (attackedDamage > 0) {
/* 124 */       if (attacked.getBuffedValue(MapleBuffStat.魔法盾) != null) {
/* 125 */         mploss = (int)(attackedDamage * attacked.getBuffedValue(MapleBuffStat.魔法盾).doubleValue() / 100.0D);
/* 126 */         hploss -= mploss;
/* 127 */         if (attacked.getBuffedValue(MapleBuffStat.终极无限) != null) {
/* 128 */           mploss = 0;
/* 129 */         } else if (mploss > attacked.getStat().getMp()) {
/* 130 */           mploss = attacked.getStat().getMp();
/* 131 */           hploss -= mploss;
         }
/* 133 */         attacked.addHPMP(-hploss, -mploss);
/* 134 */       } else if (attacked.getTotalSkillLevel(27000003) > 0) {
/* 135 */         Skill skill = SkillFactory.getSkill(27000003);
/* 136 */         MapleStatEffect effect = skill.getEffect(attacked.getTotalSkillLevel(27000003));
/* 137 */         mploss = (int)(attackedDamage * effect.getX() / 100.0D);
/* 138 */         hploss -= mploss;
/* 139 */         if (mploss > attacked.getStat().getMp()) {
/* 140 */           mploss = attacked.getStat().getMp();
/* 141 */           hploss -= mploss;
         }
/* 143 */         attacked.addHPMP(-hploss, -mploss);
/* 144 */       } else if ((attacked.getStat()).mesoGuardMeso > 0.0D) {
/* 145 */         hploss = (int)Math.ceil(attackedDamage * (attacked.getStat()).mesoGuard / 100.0D);
/* 146 */         int mesoloss = (int)(attackedDamage * (attacked.getStat()).mesoGuardMeso / 100.0D);
/* 147 */         if (attacked.getMeso() < mesoloss) {
/* 148 */           attacked.gainMeso(-attacked.getMeso(), false);
/* 149 */           attacked.cancelBuffStats(new MapleBuffStat[] { MapleBuffStat.金钱护盾 });
         } else {
/* 151 */           attacked.gainMeso(-mesoloss, false);
         }
/* 153 */         attacked.addHP(-hploss);
       } else {
/* 155 */         attacked.addHP(-hploss);
       }
     }
/* 158 */     MapleMonster pvpMob = MapleLifeFactory.getMonster(9400711);
/* 159 */     map.spawnMonsterOnGroundBelow(pvpMob, attacked.getPosition());
/* 160 */     map.broadcastMessage(MaplePacketCreator.damagePlayer(attacked.getId(), 2, pvpMob.getId(), hploss));
/* 161 */     if (isCritDamage) {
/* 162 */       player.dropMessage(6, "你对玩家 " + attacked.getName() + " 造成了 " + hploss + " 点爆击伤害! 对方血量: " + attacked.getStat().getHp() + "/" + attacked.getStat().getCurrentMaxHp());
/* 163 */       attacked.dropMessage(6, "玩家 " + player.getName() + " 对你造成了 " + hploss + " 点爆击伤害!");
     } else {
/* 165 */       player.dropTopMsg("你对玩家 " + attacked.getName() + " 造成了 " + hploss + " 点伤害! 对方血量: " + attacked.getStat().getHp() + "/" + attacked.getStat().getCurrentMaxHp());
/* 166 */       attacked.dropTopMsg("玩家 " + player.getName() + " 对你造成了 " + hploss + " 点伤害!");
     }
/* 168 */     map.killMonster(pvpMob, player, false, false, (byte)1);

/* 170 */     if (attacked.getStat().getHp() <= 0 && !attacked.isAlive()) {
/* 171 */       int expReward = attacked.getLevel() * 10 * attacked.getLevel() / player.getLevel();
/* 172 */       int gpReward = (int)Math.floor(Math.random() * 10.0D + 10.0D);
/* 173 */       if (player.getPvpKills() * 0.25D >= player.getPvpDeaths()) {
/* 174 */         expReward *= 2;
       }
/* 176 */       player.gainExp(expReward, true, false, true);
/* 177 */       if (player.getGuildId() > 0 && player.getGuildId() != attacked.getGuildId()) {
/* 178 */         WorldGuildService.getInstance().gainGP(player.getGuildId(), gpReward);
       }
/* 180 */       player.gainPvpKill();
/* 181 */       player.dropMessage(6, "你击败了玩家 " + attacked.getName() + "!! ");
/* 182 */       int pvpVictory = attacked.getPvpVictory();
/* 183 */       attacked.gainPvpDeath();
/* 184 */       attacked.dropMessage(6, player.getName() + " 将你击败!");
/* 185 */       byte[] packet = MaplePacketCreator.spouseMessage(10, "[Pvp] 玩家 " + player.getName() + " 终结了 " + attacked.getName() + " 的 " + pvpVictory + " 连斩。");
/* 186 */       if (pvpVictory >= 5 && pvpVictory < 10) {
/* 187 */         map.broadcastMessage(packet);
/* 188 */       } else if (pvpVictory >= 10 && pvpVictory < 20) {
/* 189 */         player.getClient().getChannelServer().broadcastMessage(packet);
/* 190 */       } else if (pvpVictory >= 20) {
/* 191 */         WorldBroadcastService.getInstance().broadcastMessage(packet);
       }
     }
   }

   public static synchronized void doPvP(MapleCharacter player, MapleMap map, AttackInfo attack, MapleStatEffect effect) {
/* 197 */     PvpAttackInfo pvpAttack = parsePvpAttack(attack, player, effect);
/* 198 */     int mobCount = 0;
/* 199 */     for (MapleCharacter attacked : player.getMap().getCharactersIntersect(pvpAttack.box)) {
/* 200 */       if (attacked.getId() != player.getId() && attacked.isAlive() && !attacked.isHidden() && mobCount < pvpAttack.mobCount) {
/* 201 */         mobCount++;
/* 202 */         monsterBomb(player, attacked, map, pvpAttack);
       }
     }
   }

   public static synchronized void doPartyPvP(MapleCharacter player, MapleMap map, AttackInfo attack, MapleStatEffect effect) {
/* 208 */     PvpAttackInfo pvpAttack = parsePvpAttack(attack, player, effect);
/* 209 */     int mobCount = 0;
/* 210 */     for (MapleCharacter attacked : player.getMap().getCharactersIntersect(pvpAttack.box)) {
/* 211 */       if (attacked.getId() != player.getId() && attacked.isAlive() && !attacked.isHidden() && (player.getParty() == null || player.getParty() != attacked.getParty()) && mobCount < pvpAttack.mobCount) {
/* 212 */         mobCount++;
/* 213 */         monsterBomb(player, attacked, map, pvpAttack);
       }
     }
   }

   public static synchronized void doGuildPvP(MapleCharacter player, MapleMap map, AttackInfo attack, MapleStatEffect effect) {
/* 219 */     PvpAttackInfo pvpAttack = parsePvpAttack(attack, player, effect);
/* 220 */     int mobCount = 0;
/* 221 */     for (MapleCharacter attacked : player.getMap().getCharactersIntersect(pvpAttack.box)) {
/* 222 */       if (attacked.getId() != player.getId() && attacked.isAlive() && !attacked.isHidden() && (player.getGuildId() == 0 || player.getGuildId() != attacked.getGuildId()) && mobCount < pvpAttack.mobCount) {
/* 223 */         mobCount++;
/* 224 */         monsterBomb(player, attacked, map, pvpAttack);
       }
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\maps\pvp\MaplePvp.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */